﻿using Jive.Models;
using Jive.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Jive.Helpers.TemplateSelector
{
    public class UserTemplateSelector : DataTemplateSelector
    {
        public DataTemplate MyTemplate
        {
            get;
            set;
        }
        public DataTemplate TheirTemplate
        {
            get;
            set;
        }

        public override DataTemplate SelectTemplate(
            object item, DependencyObject container)
        {
            if (System.ComponentModel.DesignerProperties.IsInDesignTool)
            {
                Random rnd = new Random((int)DateTime.Now.Ticks);
                if (rnd.Next(1, 10) >= 5)
                    return TheirTemplate;
                else
                    return MyTemplate;


            }
            MessageModel itemAux = item as MessageModel;
            if (itemAux != null)
            {
                if (itemAux.UserName== Client.ClientInstance.CurrentUserInfo.UserName || itemAux.UserName=="GreenText" || itemAux.UserName == "RedText")
                    return MyTemplate;
                else
                    return TheirTemplate;
            }

            return base.SelectTemplate(item, container);
        }
    }
}
